package bb.lanxing.lib.devices.bryton.bbcp;

//import com.parse.codec.CharEncoding;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;


public class BbcpNotification implements BbcpPackage {
    private String mKey;
    private byte mMessageId;
    private String mValue;

    @Override
    public void unpack(byte[] bArr) throws BbcpValidationException {
    }

    public BbcpNotification(byte b, String str, String str2) {
        this.mMessageId = b;
        this.mKey = str;
        this.mValue = str2;
    }

    @Override
    public byte[] pack() throws BbcpValidationException {
        int i;
        try {
            byte[] bytes = this.mKey.getBytes(StandardCharsets.US_ASCII/*CharEncoding.US_ASCII*/);
            byte[] bArr = null;
            if (!this.mValue.isEmpty()) {
                bArr = this.mValue.getBytes("UTF-8");
                i = 16;
                if (bArr.length <= 16) {
                    i = bArr.length;
                }
            } else {
                i = 0;
            }
            int i2 = i + 4;
            byte[] bArr2 = new byte[i2];
            bArr2[0] = this.mMessageId;
            System.arraycopy(bytes, 0, bArr2, 1, 2);
            if (bArr != null) {
                System.arraycopy(bArr, 0, bArr2, 3, i);
            }
            bArr2[i2 - 1] = 0;
            return bArr2;
        } catch (UnsupportedEncodingException e) {
            throw new BbcpValidationException(e.getMessage());
        }
    }
}
